package _01;

public class Solution {
	public static int replace(int N, int M, int i, int j) {
		if (i > j || j > 31)
			return N;
		int mask = ((0xFFFFFFFF << (j + 1))) ^ (0xFFFFFFFF << i);
		return N & (~mask) | (M << i);
	}

	public static void main(String... args) {
		int N = 0xAAAAAAAA;
		int M = 0x13;
		int i = 4;
		int j = 7;
		int result = replace(N, M, i, j);
		System.out.println(Integer.
				toBinaryString(result));
		System.out.println(Integer.toHexString(result));
	}
}